package top.mask.mq.utils;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import lombok.SneakyThrows;


/**
 * 为mq连接工厂创建信道工具类
 */
public class RabbitMQUtil {
    @SneakyThrows
    public static Channel getChannel(){
        //1.创建一个连接工厂
        ConnectionFactory factory = new ConnectionFactory();

        //连接mq队列
        factory.setHost("127.0.0.1");

        //用户名
        factory.setUsername("mask");

        //密码
        factory.setPassword("mask");

        //2.创建连接
        Connection connection = factory.newConnection();

        //获取信道
        Channel channel = connection.createChannel();

        return channel;
    }
}
